package com.liruo.test.spring.annotationdep;

import com.liruo.test.spring.annotationdep.bean.*;
import com.liruo.test.spring.annotationdep.bean.condidtion.Win32Condition;
import com.liruo.test.spring.annotationdep.bean.condidtion.Win64Condition;
import com.liruo.test.spring.annotationdep.bean.factorymethod.WantBeanFactoryBean;
import com.liruo.test.spring.annotationdep.bean.importbean.ThirdPartyImportBeanDefinitionRegistry;
import com.liruo.test.spring.annotationdep.bean.importbean.ThirdPartyImportSelector;
import com.liruo.test.spring.component.common.importcpt.CommonComponentByImport;
import com.liruo.test.spring.component.common.model.CommonBean;
import com.liruo.test.spring.component.likestarter.LikeStarterConfiguration;
import com.liruo.test.spring.component.third.bean.ThirdConfigurationBean;
import com.liruo.test.spring.component.third.innerconfig.ThirdInnerBean;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.*;
import org.springframework.core.annotation.Order;

/**
 * @Author:liruo
 * @Date:2022-11-20-19:31:09
 * @Desc
 */

@EnableAutoConfiguration
@Configuration
@ComponentScan(
        basePackages = {
                "com.liruo.test.spring.component.common.model",
                "com.liruo.test.spring.annotationdep"
        }
)
@Import({LikeStarterConfiguration.class, ThirdPartyImportSelector.class, CommonComponentByImport.class, ThirdPartyImportBeanDefinitionRegistry.class})
public class BeanConfiguration {
    @Scope("prototype")
    @Bean
    public ScopeBean multiBean(){
        return new ScopeBean();
    }

    @Scope("singleton")
    @Bean
    public ScopeBean SingletonBean(){
        return new ScopeBean();
    }


    @Lazy
    @Bean
    public LazyBean lazyBean(){
        System.out.println("================================load lazyBean");
        return new LazyBean();
    }

    //没有特殊设置。Order是不会生效的
    @Order(1)
    @Bean
    public OrderBean orderBean1(){
        return new OrderBean();
    }
    @Order(0)
    @Bean
    public OrderBean orderBean0(){
        return new OrderBean();
    }

    @Conditional(Win32Condition.class)
    @Bean
    public ConditionalBean Win32ConditionalBean(){
        return new ConditionalBean();
    }
    @Conditional(Win64Condition.class)
    @Bean
    public ConditionalBean Win64ConditionalBean(){
        return new ConditionalBean();
    }


    @Bean
    public WantBeanFactoryBean wantBeanFactoryBean(){
        return new WantBeanFactoryBean();
    }

    @Bean
    public CommonBean thirdPartyBean(){
        return new CommonBean();
    }

    @Configuration
    @ComponentScan(
            basePackages = {
                    "com.liruo.test.spring.component.common.innerconfig",
                    "com.liruo.test.spring.component.third.innerconfig"
            }
    )
    class TestInnerConfiguration{
        @Bean
        public InnerConfigurationBean innerConfigurationBean(){
            return new InnerConfigurationBean();
        }
        @Bean
        public ThirdInnerBean thirdInnerBean(){
            return new ThirdInnerBean();
        }
        @Bean
        public CommonBean commonBean(){
            return new CommonBean();
        }
    }
}
